﻿var navShows;
var navMembers;
var navTeams;
var navHelp;

var tools;

$(document).ready(function() {
    navShows = $("li#nav-shows");
    navMembers = $("li#nav-members");
    navTeams = $("li#nav-teams");
    navHelp = $("#nav-help");

    navShows.css("left", "0em");
    navMembers.css("left", "3em");
    navTeams.css("left", "6em");
    navHelp.css("left", "9em");

    tools = $(".tool");

    setCurrentBarTheme();
    setModifyHides();
    setToolHover();

    $("object").css("display", "block");
    $("h3").css("min-height", 100);

});


function setCurrentBarTheme() {
    var siteSection = location.href.split("/");
    for (var x = 0; x < siteSection.length; x++) {
        if(siteSection[x] != "" && siteSection[x] != "http:" && (x + 1) < siteSection.length){
            siteSection = siteSection[x + 1];
            break;
            }
    }

    var emphasis;

    switch (siteSection.toUpperCase()) {
        case "RADIOSHOWS":
            setNavStyle(navShows, "/Content/Images/emphasis_rt.png");
            setAllStyle("/Content/Images/emphasis_r.png");
            setFootStyle("/Content/Images/footbar_r.png");
            break;
        case "MEMBERS":
            setNavStyle(navMembers, "/Content/Images/emphasis_gt.png");
            setAllStyle("/Content/Images/emphasis_g.png");
            setFootStyle("/Content/Images/footbar_g.png");
            break;
        case "TEAMS":
            setNavStyle(navTeams, "/Content/Images/emphasis_pt.png");
            setAllStyle("/Content/Images/emphasis_p.png");
            setFootStyle("/Content/Images/footbar_p.png");
            break;
        default:
            $('span#displayMedia').replaceWith('<h2></h2>');
            setNavStyle(navShows, "/Content/Images/emphasis_rt.png");
            setAllStyle("/Content/Images/emphasis_r.png");
            setFootStyle("/Content/Images/footbar_r.png");
            break;
    }
}

function setNavStyle(navItem, style) {
    $(navItem).find(".bar").css({
        "background-image" : "url('" + style + "')",
        "width" : "24px",
        "height" : "17px",
        "top" : "1.1em",
        "left" : "-0.2em"
        });
    }
function setAllStyle(style) {
    $(".emphasis").css("backgroundImage", "url('" + style + "')");
}

function setFootStyle(style) {
    $("#footer-bars").css("backgroundImage", "url('" + style + "')");
}

function setModifyHides() {
    var modifyEdits = $("a.modify");
    //$(".modify-tools").css.display = "none";

 //   for (var x = 0; x < modifyEdits.length; x++) {
        //var modifyBox = next(modifyEdits[x]);
        //if (modifyBox.className == "modify-tools") {
    $("a.modify").livequery('click', function() {
        var $modifyBox = $(this).next(".modify-tools");
        
        $modifyBox.slideDown(400, null);
        $modifyBox.css("display", "block");
        return false;
    });
        //}
   // }
}

function setToolHover() {
    tools.mouseover(function() {
        $(this).animate({
        opacity: 0.4
    }, 100);
});
    
    tools.mouseout(function() {
        $(this).animate({
            opacity: 1
        },100);
    });
}

function next(elem) {
    do {
        elem = elem.nextSibling;
    } while (elem && elem.nodeType != 1);
    return elem;
}

jQuery.fn.replaceWith = function(replacement) {
    return this.each(function() {
        element = $(this);
        $(this)
        .after(replacement).next()
        .attr('class', element.attr('class')).attr('id', element.attr('id'))
        .html(element.html())
        .prev().remove();
    });
};
